<template>
  <div class="app-container">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="主题" prop="elSubject">
          <el-input v-model="form.elSubject" placeholder="请输入主题" />
        </el-form-item>
        <el-form-item label="内容">
          <editor v-model="form.elMessage" :min-height="192"/>
        </el-form-item>
        <el-form-item label="发送人" prop="elSend">
          <el-input v-model="form.elSend" placeholder="请输入发送人" />
        </el-form-item>
        <el-form-item label="接收人" prop="elRecive">
          <el-input v-model="form.elRecive" placeholder="请输入接收人" />
        </el-form-item>
        <el-form-item label="抄送人" prop="elCopy">
          <el-input v-model="form.elCopy" placeholder="请输入抄送人" />
        </el-form-item>
        <el-form-item label="定时发送" prop="elSetTime">
          <el-date-picker clearable
            v-model="form.elSetTime"
            type="datetime"
            value-format="yyyy-MM-dd"
            placeholder="请选择定时发送">
          </el-date-picker>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>

  </div>
</template>

<script>
import { addEmail } from "@/api/system/email";

export default {
  name: "Email",
  data() {
    return {
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        elSubject: [
          { required: true, message: "主题不能为空", trigger: "blur" }
        ],
        elMessage: [
          { required: true, message: "内容不能为空", trigger: "blur" }
        ],
        elSend: [
          { required: true, message: "发送人不能为空", trigger: "blur" }
        ],
        elRecive: [
          { required: true, message: "接收人不能为空", trigger: "blur" }
        ],
      }
    };
  },
  methods: {

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        elId: null,
        elSubject: null,
        elMessage: null,
        elSend: null,
        elRecive: null,
        elCopy: null,
        elSetTime: null,
        elState: null,
        elSendTime: null,
        elResult: null,
        updateTime: null,
        createTime: null,
        createBy: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          const username = this.$store.state.user.name;
          this.form.createBy=username
            addEmail(this.form).then(response => {
              this.$modal.msgSuccess("提交成功");
              this.open = false;
              this.reset();
            });
        }
      });
    }
  }
};
</script>
